﻿using Volo.Abp.DependencyInjection;
using YAPACS.BusinessObjects.Exams;
using YAPACS.Workflows;

namespace YAPACS.RisServer.Workflows.Register;

public class BeforeSubmit : WorkflowBase, IBeforeSubmit, ITransientDependency
{
    protected override async Task<WorkflowOutput> InvokeCoreAsync(WorkflowInput input)
    {
        const string key = "Exam";
        if (input.ContainsKey(key) && input.GetValueOrDefault(key) is Exam exam)
        {
            if (exam.ExamDevice == null && exam.ExamCategory == null)
            {
                throw new Exception("请选择【检查设备】或【检查类别】");
            }

            return await Task.FromResult(new WorkflowOutput() { Success = true });
        }
        return new WorkflowOutput
        {
            Success = false,
            Error = "未获取到检查数据"
        };
    }
}
